<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery-3.1.1.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>手术安排</title>
<style type="text/css">
.cc_item {
	padding: 10px;
}
</style>
</head>
<body>
<script>
		var cc_mycolumns = [[
	             		{field:'arrangeid',width:'6%',checkbox:true,title:'手术编号'},
	            		    {field:'adoctoridname',width:'13%',title:'手术安排人'},
	             		{field:'arrdoctorridname',width:'12%',title:'主刀医生'},
	            		    {field:'saddress', width:'14%',title:'手术室地址'},
	             		{field:'pname', width:'12%',title:'手术病人'},
	            		    {field:'surname', width:'16%',title:'手术名称'},
	             		{field:'fixdate',width:'10%',title:'安排时间'},
	             		{field:'arrdate',width:'10%',title:'处理时间'},
	            		    {field:'astate', width:'10%',title:'手术状态'}
	                 ]];

function arrangereject(){
	var rows = $('#cc_update_arrange_dg').datagrid('getRows');
	//deleteRow
	//alert(rows.length);
	for(var i=0;i<rows.length;i++){
		var cc_index =$('#cc_update_arrange_dg').datagrid('getRowIndex', rows[i]);
		$('#cc_update_arrange_dg').datagrid('deleteRow',cc_index);
	}
}

function cc_savearrange() {
	//将datagrid中的数据行保存到隐式表单域中
	var  shenpi_staffId = $("#tontyiStaffId").html();

	$("#cc_arrange_heDoctorid").val(shenpi_staffId);
	//1、获取新增的数据行
	var rows = $('#cc_update_arrange_dg').datagrid('getRows');
	console.log(JSON.stringify(rows));
//
	//为每一行生成对应的隐藏表单域
	//list.eleCheckName
	for (var i = 0; i < rows.length; i++) {
		cc_arrangeHidden(rows[i], "sdnanaid", i);
		cc_arrangeHidden(rows[i], "sdnananame", i);
		
	}
	
	var ff_plan = $("#cc_eait_arrange_form");
	//提交表单
	ff_plan.form("submit", {
		success : function(data) {
			var json = eval("(" + data + ")");
			$.messager.alert("提示", json.reason);
			$("#cc_eait_arrange_win").window('close');
			
			$(":hidden[x='y']").remove();
			$(this).form("clear");
			$("#cc_show_arrange_dg").datagrid("reload");
		}
	});
}

function cc_arrangeHidden(row, name, i) {
	//details.planDetail
	var ff_plan = $("#cc_eait_arrange_form");
	$("<input type='hidden' x='y'>").attr("name",
			"list[" + i + '].' + name).val(row[name])
			.appendTo(ff_plan);
}
function cc_arrangerowStlye(index,row){
	//alert(new Date());
	var date = new Date();
    var seperator1 = "/";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    if (row.fixdate==currentdate||row.arrdate==currentdate){
		return 'background-color:#CCFF99;color:red;';
		
	}
}
</script>
<script type="text/javascript">
	$(function(){
		var  shenpi_staffId = $("#tontyiStaffId").html();
		$("#cc_show_arrange_dg").propertygrid({
			url:'tocc_queryAllCcArrange',
			queryParams : {
				pdid : shenpi_staffId
			}
		});
		//cc_eait_arrange_win
		var val=shenpi_staffId;
		//tocc_queryAllCcArrange
		
		//cc_arrange_acostid患者
		$("#cc_arrange_acostid").combogrid({
			url:'tocc_queryBypadoctorid',
			queryParams : {
				padoctorid : val
			}
		});
		//cc_arrange_arrdoctorrid主刀医生
		$("#cc_arrange_arrdoctorrid").combogrid({
			url:'tocc_qureyBypostNo',
			queryParams : {
				postNo : 1
			}
		});
		//cc_update_addOnearrange助理人员
		$("#cc_update_addOnearrange").combobox({
			url:'tocc_qureyBypostNo',
			queryParams : {
				postNo : 2
			}
		});
		//cc_arrange_asurgeryid手术室
		//cc_arrange_ccsid手术名称
		
		$("#cc_Arrange_addOne").linkbutton({
			onClick:function(){
				$("#cc_eait_arrange_win").window({
					title:"安排手术"
				});
				arrangereject();
				$("#cc_eait_arrange_form").form("clear");
				$("#cc_eait_arrange_win").window("open");
			}
		});
		//cc_update_arrange_save提交修改
		$("#cc_update_arrange_save").linkbutton({
			onClick:function(){
				var rows = $('#cc_update_arrange_dg').datagrid('getRows');
				if(rows.length>0){
					cc_savearrange();
					
				}else{
					$.messager.alert("提示", "请给此手术添加助理人员！");
				}
			}
		});
		//cc_update_arrange_add添加助理
		$("#cc_update_arrange_add").linkbutton({
			onClick:function(){
				$("#cc_update_addOnearrange_win").window("open");
			}
		});
		//cc_update_arrange_del删除
		$("#cc_update_arrange_del").linkbutton({
			onClick:function(){
				var rows =$("#cc_update_arrange_dg").datagrid("getSelections");
				if(rows.length>0){
					$.messager.confirm("提示", "确定要删除吗？", function(v){
						if(v){
							
							var rows =$("#cc_update_arrange_dg").datagrid("getSelections");
							//deleteRow
							for(var i=0;i<rows.length;i++){
								//alert(i);
								var cc_index =$('#cc_update_arrange_dg').datagrid('getRowIndex', rows[i]);
								$('#cc_update_arrange_dg').datagrid('deleteRow',cc_index);
							}
						}
					});
				}else{
					$.messager.alert("提示", "请选择您想删除的助理人员！");
				}
			}
		});
		//var rows = $('#cc_arrange_scheduledetail_tt').datagrid('getChanges');
		//cc_update_addOnearrange_save添加保存
		$("#cc_update_addOnearrange_save").linkbutton({
			onClick:function(){
				var zhuliid=$("#cc_update_addOnearrange").combobox("getValue");
				var zhuliName=$("#cc_update_addOnearrange").combobox("getText");
				if(zhuliid.length!=0){
					var rows=$("#cc_update_arrange_dg").datagrid("getRows");
					var zhuli_jg=false;
					for(var i=0;i<rows.length;i++&&zhuli_jg==false){
						if(rows[i].sdnanaid==zhuliid){
							zhuli_jg=true;
						}
					}
					if(zhuli_jg==false){
						$("#cc_update_arrange_dg").datagrid('appendRow',{
							sdnanaid:zhuliid,
							sdnananame:zhuliName
						});
					}else{
						$.messager.alert("提示", "助理人员'"+zhuliName+"'已经存在！");
					}
					$("#cc_update_addOnearrange_form").form("clear");
					$("#cc_update_addOnearrange_win").window("close");
				}
			}
		});
		//cc_update_addOnearrange_cal取消添加
		$("#cc_update_addOnearrange_cal").linkbutton({
			onClick:function(){
				$("#cc_update_addOnearrange_form").form("clear");
				$("#cc_update_addOnearrange_win").window("close");
			}
		});
		//cc_Arrange_updateOne修改
		$("#cc_Arrange_updateOne").linkbutton({
			onClick:function(){
				//var rows =$("#cc_update_arrange_dg").datagrid("getSelections");
				var rows = $("#cc_show_arrange_dg").propertygrid("getSelections");
				if (rows.length == 1) {
					var ccarrangeid=rows[0].arrangeid;
					$("#cc_eait_arrange_win").window({
						title:"手术信息修改"
					});
					$.getJSON("tocc_queryOneByCcArrangeId", {"id" : ccarrangeid }, function(data) {
						//$(pharStockMed.target).text("setValue",date);
						$("<form id='ddd_dddd' type='hidden'>").appendTo($("body"));
						
						$("<input id='cc_arrdoctorrid' name='arrdoctorrid'>").appendTo($("#ddd_dddd"));
						$("<input id='cc_asurgeryid' name='asurgeryid'>").appendTo($("#ddd_dddd"));
						$("<input id='cc_ccsid' name='ccsid'>").appendTo($("#ddd_dddd"));
						$("<input id='cc_adoctorid' name='adoctorid'>").appendTo($("#ddd_dddd"));
						$("<input id='cc_acostid' name='acostid'>").appendTo($("#ddd_dddd"));
						$("#ddd_dddd").form("load", data);
						//name="arrdoctorrid" name="asurgeryid" name="ccsid"
						//name="adoctorid"name="acostid"
						$("#cc_arrange_acostid").combogrid("setValue",$("#cc_acostid").val());
						$("#cc_arrange_acostid").combogrid("setText",rows[0].pname);
						$("#cc_arrange_arrdoctorrid").combogrid("setValue",$("#cc_arrdoctorrid").val());
						$("#cc_arrange_arrdoctorrid").combogrid("setText",rows[0].arrdoctorridname);
						$("#cc_arrange_asurgeryid").combogrid("setValue",$("#cc_asurgeryid").val());
						$("#cc_arrange_asurgeryid").combogrid("setText",rows[0].saddress);
						$("#cc_arrange_ccsid").combogrid("setValue",$("#cc_ccsid").val());
						$("#cc_arrange_ccsid").combogrid("setText",rows[0].surname);
						$("#ddd_dddd").remove();
						$("#cc_arrang_arrangeid").val(ccarrangeid);
					});
					$("#cc_update_arrange_dg").datagrid({
						url:'tocc_qureyByschId',
						queryParams : {
							schId : ccarrangeid
						}
					});
					$("#cc_eait_arrange_win").window("open");
					
				}else{
					$.messager.alert("提示", "只能选择一条记录，您目前选择了"
							+ rows.length + "条!");
				}
			}
		});
		//cc_Arrange_delete取消
		$("#cc_Arrange_delete").linkbutton({
			onClick:function(){
				var rows =$("#cc_show_arrange_dg").propertygrid("getSelections");
				if(rows.length>0){
					$.messager.confirm("提示", "确定要取消吗？", function(v){
						if(v){
							//var rows =$("#cc_show_arrange_dg").datagrid("getSelections");
							//deleteRow
							var arr = [];
							var caljg=false;
							for(var i = 0; i < rows.length; i ++){
								if(rows[i].astate=='已处理'){
									caljg=true;
								}else if(rows[i].astate=='已取消'){
									caljg=true;
								}else{
									caljg=false;
								}
								if(caljg==false){
									arr.push(rows[i].arrangeid);
								}
							}
							//用form提交
							$('<form>').form('submit', {
							    url:'dellistCcArrange',
							    onSubmit: function(param){
							    	param.list=arr;
							    },
							    success:function(data){
							    	
							    	var json = eval("(" + data + ")");
									$.messager.alert("提示", json.reason);
									$("#cc_show_arrange_dg").propertygrid("reload");
							    }
							});
						
						}
					});
				}else{
					$.messager.alert("提示", "请选择您想取消的手术安排！");
				}
			}
		});
		//cc_Arrange_reload刷新
		$("#cc_Arrange_reload").linkbutton({
			onClick:function(){
				$("#cc_show_arrange_dg").propertygrid({
					url:'tocc_queryAllCcArrange',
					queryParams : {
						pdid : val
					}
				});
				$("#cc_show_arrange_dg").propertygrid({
					groupField:'astate'
				});
			}
		});
		
		//cc_Arrange_okOne完成手术
		$("#cc_Arrange_okOne").linkbutton({
			onClick:function(){
				var rows =$("#cc_show_arrange_dg").propertygrid("getSelections");
				if(rows.length==1){
							//var rows =$("#cc_show_arrange_dg").datagrid("getSelections");
							//deleteRow
					var ccStaffName=$("#cc_staffName").html();
					if(rows[0].arrdoctorridname==ccStaffName){
						var arr = [];
						var caljg=false;
						for(var i = 0; i < rows.length; i ++&&caljg==false){
							//alert(rows[i].astate);
							if(rows[i].astate=='已处理'){
								caljg=true;
							}else if(rows[i].astate=='已取消'){
								caljg=true;
							}else{
								caljg=false;
							}
							if(caljg==false){
								arr.push(rows[i].arrangeid);
							}
						}
						//用form提交
						$('<form>').form('submit', {
						    url:'oklistCcArrange',
						    onSubmit: function(param){
						    	param.list=arr;
						    },
						    success:function(data){
						    	var json = eval("(" + data + ")");
								$.messager.alert("提示", json.reason);
								$("#cc_show_arrange_dg").propertygrid("reload");
						    }
						});
					}else{
						$.messager.alert("提示", "该手术的主刀医生不是你，不能执行本操作！");
					}
							
				}else{
					$.messager.alert("提示", "只能选择一条记录，您目前选择了"
							+ rows.length + "条!");
				}
			}
		});
		//tocc_queryfindByastate
		//cc_Arrange_showwei查看未处理
		/* $("#cc_Arrange_showwei").linkbutton({
			onClick:function(){
			$("#cc_show_arrange_dg").datagrid({
				url:'tocc_queryfindByastate',
					queryParams : {
						pdid : val
					}
				});
			}
		}); */
		//搜索
		$('#cc_Arrange_search').searchbox({
			searcher : function(value, name) {
				if (name == "病人姓名") {
					$("#cc_show_arrange_dg").propertygrid({
						url : 'tocc_queryfindBypatientName',
						queryParams : {
							pdid : val,
							pname : value
						}
					});
				}else if (name == "安排人") {
					$("#cc_show_arrange_dg").propertygrid({
						url : 'tocc_queryfindByStaffname',
						queryParams : {
							pdid : val,
							sname : value
						}
					});
				} else {
					$("#cc_show_arrange_dg").propertygrid({
						url : 'tocc_queryfindByStaffName',
						queryParams : {
							pdid : val,
							sname : value
						}
					});
				}
				$("#cc_show_arrange_dg").propertygrid({
					groupField:'astate'
				});
				//false
			}
		});
	});
	       
</script>
<div id="cc_staffName" style="display: none;">${staffName}</div>
<table id="cc_show_arrange_dg" class="easyui-propertygrid"
		data-options="
							fitColumns:true,
							fit:true,
							showGroup:true,
							pagination:true,
							striped:true,
							singleSelect:false,
							border:false ,
							toolbar:'#cc_Arrange_btn',
							pageSize: 13,
							pageList:[13,26,39,52],
							border:false,
							columns: cc_mycolumns,
							groupField:'astate',
							rowStyler: cc_arrangerowStlye
						">
	</table>
	<div id="cc_Arrange_btn">
			<a id="cc_Arrange_addOne" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">安排手术</a> <a
			id="cc_Arrange_updateOne" class="easyui-linkbutton"
			data-options="iconCls:'icon-tiaozheng',plain:true">手术调整</a>
			<a id="cc_Arrange_okOne" class="easyui-linkbutton"
			data-options="iconCls:'icon-ok',plain:true">完成手术</a>
			<a id="cc_Arrange_delete" class="easyui-linkbutton"
			data-options="iconCls:'icon-remove',plain:true">取消手术</a>
			<a id="cc_Arrange_reload" class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a><input
			id="cc_Arrange_search" class="easyui-searchbox"
			data-options="menu:'#cc_Arrangeee',width:220,prompt:'请输入你要查找的内容'">
	</div>
	<div id="cc_Arrangeee" style="width: 90px">
		<div date-options="name:'name'">安排人</div>
		<div date-options="name:'name'">主刀医生</div>
	</div>
<div id="cc_eait_arrange_win" class="easyui-window"
		style="padding: 0px; line-height: 150%;"
		data-options="
			iconCls:'icon-banliyewu',
		     width: 530,
		     height: 400,
		     closed: true,
		      modal:true,
		     title:'安排手术'
			">

		<form id="cc_eait_arrange_form" action="tocc_addCcArrangeScheduledetail" method="post">
			<div style="display: none">
				<input id="cc_arrange_heDoctorid" name="arrange.adoctorid" 
					value="1">
					<input id="cc_arrang_arrangeid" name="arrange_id" >
			</div>
			<div class="cc_item"
				style="background: rgb(236, 243, 255); padding: 10px;  margin: 0px">
				<select id="cc_arrange_acostid" name="arrange.acostid" 
					class="easyui-combogrid"
					data-options="
							labelAlign:'right', width: 200,
							label:'患者:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '患者不能为空',
							panelWidth: '243',
							idField: 'patientid',
							textField: 'pname',
							columns: [[
								{field: 'patientid', title: '患者编号', width: 80},
								{field: 'icid', title: '患者IC卡号', width: 80},
								{field: 'pname', title: '患者姓名', width: 80},
							]]
						"></select>
				<select id="cc_arrange_arrdoctorrid" name="arrange.arrdoctorrid" 
					class="easyui-combogrid"
					data-options="
							labelAlign:'right', width: 200,
							label:'主刀医生:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '主刀医生不能空',
							panelWidth: '223',
							idField: 'staffNo',
							textField: 'staffName',
							columns: [[
								{field: 'staffNo', title: '医生编号', width: 80},
								{field: 'staffName', title: '医生姓名', width: 80},
								{field: 'staffPostNo', title: '职务', width: 60},
							]]
						"></select>
			</div>
			<div class="cc_item"
				style="background: rgb(236, 243, 255); padding-bottom: 10px; margin: 0px">
				<select id="cc_arrange_asurgeryid" name="arrange.asurgeryid" 
					class="easyui-combogrid"
					data-options="
							labelAlign:'right', width: 210,
							label:'手术室:',
							panelHeight: 'auto',
							required: true,
							url:'tocc_queryAllCcSurgery',
     						missingMessage: '手术室不能为空',
							panelWidth: '153',
							idField: 'surgeryid',
							textField: 'saddress',
							columns: [[
								{field: 'surgeryid', title: '手术室编号', width: 70},
								{field: 'saddress', title: '手术室地址', width: 80},
							]]
						"></select>
				<select id="cc_arrange_ccsid" name="arrange.ccsid" 
					class="easyui-combogrid"
					data-options="
							labelAlign:'right', width: 200,
							label:'手术名称:',
							panelHeight: 'auto',
							required: true,
     						missingMessage: '手术名称不能空',
							panelWidth: '243',
							url: 'tocc_queryAllCcSunmoney',
							idField: 'ccsid',
							textField: 'ccsname',
							columns: [[
								{field: 'ccsid', title: '手术编号', width: 60},
								{field: 'ccsname', title: '手术名称', width: 120},
								{field: 'sunmoney', title: '手术费用', width: 60},
							
							]]
						"></select>
			</div>
			<div style="margin: 5px;">
				<div id="cc_arrange_scheduledetail_tt" class="easyui-tabs"
					style="width: 100%; margin-top: 10px;"
					data-options="plain:true,narrow:true">
					<div title="手术助理人员" style="padding: 10px;">
						<table id="cc_update_arrange_dg" class="easyui-datagrid"
							style="height: auto"
							data-options="
								iconCls: 'icon-edit',
								method: 'get',
								toolbar: '#cc_update_arrange_tb',
								width: '100%'
							">
							<thead>
								<tr>
									<th data-options="field:'tt',checkbox:true"></th>
									
									<th data-options="field:'sdnanaid',width:'55%',align:'center'">员工编号</th>
									<th data-options="field:'sdnananame',width:'40%',align:'center'">助理姓名</th>
								</tr>
							</thead>
						</table>

						<div id="cc_update_arrange_tb" style="height: auto">
							<a id="cc_update_arrange_add" class="easyui-linkbutton"
								data-options="iconCls:'icon-add',plain:true" onclick="">添加人员</a>
							<a id="cc_update_arrange_del" class="easyui-linkbutton"
								data-options="iconCls:'icon-remove',plain:true" onclick="">删除人员</a>
							<a id="cc_update_arrange_save"
								class="easyui-linkbutton"
								data-options="iconCls:'icon-baocun',plain:true" onclick=""
								style="margin-left: 130px">提交安排</a>
						</div>
					</div>
					
				</div>
			</div>
		</form>
	</div>
<div id="cc_update_addOnearrange_win" class="easyui-window"
		style="padding: 0px; line-height: 150%;background: rgb(236,243,255);"
		data-options="iconCls:'icon-banliyewu',
		     width: 300,
		     height: 120,
		     closed: true,
		      modal:true,
		     title:'添加助理人员'
			">
			<form id="cc_update_addOnearrange_form" action="" method="post">
			<div style="display: none">
					<input id="updatecheckcprId"> 
					<input id="updatecheckcprNum">
				</div>
			<div class="cc_item">
				<select id="cc_update_addOnearrange" class="easyui-combobox" data-options="
					labelAlign:'right',
					label:'助理人员:',
					width:260,
					panelHeight: 'auto',
					panelWidth: '200',
					valueField:'staffNo',
                    textField:'staffName'"
					></select>
			</div>
			<div style="margin-left: 20%; padding-top: 5px">
				<a id="cc_update_addOnearrange_save" class="easyui-linkbutton" data-options="iconCls:'icon-baocun'">确定</a> 
				<a id="cc_update_addOnearrange_cal" style="margin-left: 40px" class="easyui-linkbutton" data-options="iconCls:'icon-chexiao'">取消</a>
			</div>
			</form>
	</div>
</body>
</html>